import axios from 'axios';

const leavingMsg = {
  //获取留言配置信息
  getMsgConfig: function (token, callback) {
    this.publicAxiosMsg('/home/MessageConfig/read?token=' + token, {}, callback);
  },

  //添加工单
  updatedConfig: function (title, depiction,customer_id, classify_id,source,token, callback) {
    //添加工单
    this.publicAxiosPostMsg('/home/WorkOrders/save?token='+token, {
      title: title,             //标题
      depiction: depiction,     // 问题的描述
      customer_id:customer_id,     //相关客户 -- 当前客户的id
      classify_id: classify_id,    //分类
      source:source                //来源
    }, callback);
  },



  //提交用户信息
  submitInfor: function (token, id, nickname, email, phone, callback) {
    this.publicAxiosPostMsg('/home/customers/update?token=' + token, {
      id: id,
      nickname: nickname,
      email: email,
      phone: phone
    }, callback);
  },

  //公共get接口
  publicAxiosMsg: function (methods, data, success, error) {
    axios.get(process.env.API_URL + methods, data).then(function (res) {
      if (success) {
        success(res.data);
      }
    }).catch(function (error) {
      console.log(error)
      if (error) {
        error(error);
      }
      ;
    });
  },

  //公共post接口
  publicAxiosPostMsg: function (methods, data, success, error) {
    axios.post(process.env.API_URL + methods, data).then(function (res) {
      if (success) {
        success(res.data);
      }
    }).catch(function (error) {
      console.log(error);
      if (error) {
        error(error);
      }
    });
  },

  //获取工单自定义分类
  getPostmsg: function (token,callback) {
    this.publicAxiosPostMsg('/home/workorderclassify?token='+token, {},callback);
  },

  //添加工单的function
  publicAxiosPostdept: function (methods, {}, success, error) {
    axios.post(process.env.API_URL + methods, {}).then(function (res) {
      if (success) {
        success(res.data);
      }
    }).catch(function (err) {
      console.log(err);
      if (error)
        error(err);
    });
  }

};
export default leavingMsg;
